#!/usr/bin/sh

MRUBY_PACKAGE_DIR=$(dirname "$(dirname "$(readlink -f "$0")")")

print_help()
{
  echo "Usage: mruby-config [switches]"
  echo "  switches:"
  echo "  --cc                        print C compiler name"
  echo "  --cflags                    print flags passed to C compiler"
  echo "  --cxx                       print C++ compiler name"
  echo "  --cxxflags                  print flags passed to C++ compiler"
  echo "  --as                        print assembler name"
  echo "  --asflags                   print flags passed to assembler"
  echo "  --objc                      print Objective C compiler name"
  echo "  --objcflags                 print flags passed to Objective C compiler"
  echo "  --ld                        print linker name"
  echo "  --ldflags                   print flags passed to linker"
  echo "  --ldflags-before-libs       print flags passed to linker before linked libraries"
  echo "  --libs                      print linked libraries"
  echo "  --libmruby-path             print libmruby path"
  echo "  --help                      print this help"
  exit 0
}

if [ $# -eq 0 ]; then
   print_help
fi

while [ $# -gt 0 ]; do
  case $1 in
    --cc) echo gcc;;
    --cflags) echo -std=gnu99 -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=z13 -mtune=z14 -fasynchronous-unwind-tables -fstack-clash-protection   -fPIC -DMRB_DEBUG -DMRB_USE_SET -DHAVE_MRUBY_IO_GEM -DMRB_USE_RATIONAL -DMRB_USE_COMPLEX -DMRB_USE_BIGINT -DMRB_USE_DEBUG_HOOK -I"${MRUBY_PACKAGE_DIR}/include";;
    --cxx) echo g++;;
    --cxxflags) echo -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=z13 -mtune=z14 -fasynchronous-unwind-tables -fstack-clash-protection   -fPIC -DMRB_DEBUG -DMRB_USE_SET -DHAVE_MRUBY_IO_GEM -DMRB_USE_RATIONAL -DMRB_USE_COMPLEX -DMRB_USE_BIGINT -DMRB_USE_DEBUG_HOOK -I"${MRUBY_PACKAGE_DIR}/include";;
    --as) echo gcc;;
    --asflags) echo -std=gnu99 -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=z13 -mtune=z14 -fasynchronous-unwind-tables -fstack-clash-protection   -fPIC -DMRB_DEBUG -DMRB_USE_SET -DHAVE_MRUBY_IO_GEM -DMRB_USE_RATIONAL -DMRB_USE_COMPLEX -DMRB_USE_BIGINT -DMRB_USE_DEBUG_HOOK -I"${MRUBY_PACKAGE_DIR}/include";;
    --objc) echo gcc;;
    --objcflags) echo -std=gnu99 -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=z13 -mtune=z14 -fasynchronous-unwind-tables -fstack-clash-protection   -fPIC -DMRB_DEBUG -DMRB_USE_SET -DHAVE_MRUBY_IO_GEM -DMRB_USE_RATIONAL -DMRB_USE_COMPLEX -DMRB_USE_BIGINT -DMRB_USE_DEBUG_HOOK -I"${MRUBY_PACKAGE_DIR}/include";;
    --ld) echo gcc -fuse-ld=lld;;
    --ldflags) echo -Wl,-z,relro -Wl,--as-needed   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-hardened-ld-errors -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes  -lm -fuse-ld=lld -L${MRUBY_PACKAGE_DIR}/lib;;
    --ldflags-before-libs) ;;
    --libs) echo -lmruby -lm;;
    --libmruby-path) echo ${MRUBY_PACKAGE_DIR}/lib/libmruby.a;;
    *) print_help;;
  esac
  shift
done
